/*
 Here are two functions - one of them shows the time of an error,
 * another one print an error, its type and other parameters to the file.
 * Possible types: LOG_ACCESS, LOG_ERROR, ...
 * Author: Marina Kaznacheeva
 */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

FILE * fn;
int tag = 0;

char* printTime() {
    time_t now;
    char *buf;
     
    time(&now);
    buf = (char*)malloc(strlen(ctime(&now)) + 1);
     
    snprintf(buf,strlen(ctime(&now)),"%s ", ctime(&now));
    
    return buf;
} 

void logWrite(char* errType, char* time, char* srcFile, int line, char* message) {
	fn = fopen ("log.txt","a+");
	if (fn != NULL)
	{
		fprintf(fn, "[ tag = %d ][ %s ] > %s > [%s][line %d] > %s", tag, errType, time, srcFile, line, message);
		fputc('\n', fn);
		fclose(fn);
		tag++;
	}
	return;
}
